class Solution {
    int[] dx = {0, 1};
    int[] dy = {1, 0};
    int m = 0;
    int n = 0;
    int ret = 0;
    boolean[][] check;
    public int wardrobeFinishing(int mm, int nn, int cnt) {
        m = mm;
        n = nn;
        check = new boolean[m][n];
        dfs(0, 0, cnt);

        return ret;
    }
    public void dfs(int i, int j, int cnt){
        if(digit(i) + digit(j) > cnt){
            return;
        }
        check[i][j] = true;
        ret++;
        for(int k = 0; k < 2; k++){
            int x = i + dx[k];
            int y = j + dy[k];
            if(x >= 0 && x < m && y >= 0 && y < n && check[x][y] == false){
                dfs(x, y, cnt);
            }
        }
    }
    private int digit(int num){
        int sum = 0;
        while(num > 0){
            sum += (num % 10);
            num /= 10;
        }
        return sum;
    }
}